<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>ERP管理系统</title>
    <th:block th:include="include::header"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" id="role_id" name="role_id"
                   class="layui-input" th:value="${role.roleId}">

            <div class="layui-form-item">
                <label for="role_name" class="layui-form-label">
                    角色名
                </label>
                <div class="layui-input-inline">

                    <input type="text" th:if="${role.roleName!='超级管理员'}" id="role_name" name="role_name" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${role.roleName}">
                    <input type="text" th:if="${role.roleName=='超级管理员'}"  name="role_name" readOnly="true"
                           autocomplete="off" class="layui-input" th:value="${role.roleName}">
                </div>

            </div>

            <div class="layui-form-item">
                <label for="role_type" class="layui-form-label">
                    状态
                </label>
                <div class="layui-input-inline">
                    <select type="" id="role_type" name="role_type" required="" lay-verify="required"
                            autocomplete="off" class="layui-input">
                        <option value="0" th:selected="${role.roleLockout==0?'true':'false'}">锁定</option>
                        <option value="1" th:selected="${role.roleLockout==1?'true':'false'}">有效角色</option>
                    </select>
                </div>
            </div>

                <div class="layui-form-item" th:each="item:${submenus}" th:if="${item.powerCount!=0&&item.powerCount!=null}">
                    <label class="layui-form-label">[[${item.name}]]:</label>
                    <div class="layui-input-block">
                        <th:block th:if="${powers!=null}">
                            <th:block  th:each="item1:${powers}" th:if="${item1.parent==item.name}">
                                <input th:ids="${item1.powerId}" type="checkbox" th:name="${item1.type}" th:title="${item1.name}" checked="checked">
                            </th:block>
                        </th:block>

                        <th:block th:each="item2:${powers1}" th:if="${item2.parent==item.name}">
                            <input th:ids="${item2.powerId}" type="checkbox" th:name="${item2.type}" th:title="${item2.name}">
                        </th:block>
                    </div>
                </div>



            <div class="layui-form-item">
                <button  class="layui-btn" lay-filter="preservation" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
</div>
</body>
<script >
    layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;


        //监听提交
        form.on('submit(preservation)',
            function(data) {
            var inputs=$("input[type='checkbox']");
            var ins=[];
                for (var i=0;i<inputs.length;i++) {
                    if(inputs[i].checked==true){
                        ins.push(inputs[i].getAttribute("ids"))
                    }
                }
                var ids=JSON.stringify(ins);
                $.post("/user/power",{
                    "ids":ids,
                    "roleName":data.field.role_name,
                    "roleLockout":data.field.role_type,
                    "roleId":data.field.role_id
                },function(res){
                    if(res.success){
                        layer.alert(res.msg, {
                                icon: 6
                            },
                            function() {
                                //关闭当前frame
                                xadmin.close();

                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });

                    }else{
                        debugger
                        layer.alert(res.msg, {icon:5});
                        return;
                    }
                });
                return false;
            });

    });</script>
</html>